<?php

namespace App\Model\Setting;

use Illuminate\Database\Eloquent\Model;

/**
 *  临时配置
 */
class TmpSetting extends Model
{
    protected $table = 'tmp_setting';
    protected $fillable = ['setting_type', 'setting_value'];

    static function getExtraPayOn()
    {
        $item = self::where('setting_type', 'extra_pay_on')->first();
        return !$item ? 0 : intval($item->setting_value);
    }

    static function getExtraPayTotal()
    {
        $item = self::where('setting_type', 'extra_pay_total')->first();
        return !$item ? 0 : intval($item->setting_value);
    }

    static function getExtraRateValue()
    {
        $item = self::where('setting_type', 'ex_rate_value')->first();
        return !$item ? 0 : intval($item->setting_value);
    }

    static function getExtraMultiple()
    {
        $item = self::where('setting_type', 'ex_multiple')->first();
        return !$item ? 2 : intval($item->setting_value);
    }

    static function setPayInfo($info)
    {
        isset($info['extra_pay_total']) && self::where('setting_type', 'extra_pay_total')->limit(1)->update(['setting_value' => $info['extra_pay_total']]);
        isset($info['extra_pay_on']) && self::where('setting_type', 'extra_pay_on')->limit(1)->update(['setting_value' => $info['extra_pay_on']]);
        isset($info['ex_rate_value']) && self::where('setting_type', 'ex_rate_value')->limit(1)->update(['setting_value' => $info['ex_rate_value']]);
        isset($info['ex_multiple']) && self::where('setting_type', 'ex_multiple')->limit(1)->update(['setting_value' => $info['ex_multiple']]);
        return 1;
    }
}
